package com.example.marketing.web.controllers;

import com.example.user.api.dto.User;
import com.example.user.api.service.UserClient;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class GreetingController {

	@Autowired
	private UserClient userClient;

	@GetMapping("/hello")
	public String index() {
		return "index";
	}
	
	@GetMapping("/hello/{userId}")
	public String hello(@PathVariable("userId") long userId) {
		User user = userClient.getUserById(userId);

		if (user == null || !StringUtils.hasLength(user.getName())) {
			return "Hello, 匿名者";
		}

		return "Hello, " + user.getName();
	}
}
